home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac: Not for Sale / Another.not.for.sale (Australia).iso / fade into you / getting there / Apps / AuthMan 1.0.8 / AuthMan XCMD / xcmd.c < prev   
C/C++ Source or Header  |  1993-11-19  |  5KB  |  196 lines

  1. /*
  2.  * Copyright (c) 1992-1993 Regents of The University of Michigan.
  3.  * All Rights Reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and
  6.  * its documentation for any purpose and without fee is hereby granted,
  7.  * provided that the above copyright notice appears in all copies and
  8.  * that both that copyright notice and this permission notice appear
  9.  * in supporting documentation, and that the name of The University
  10.  * of Michigan not be used in advertising or publicity pertaining to
  11.  * distribution of the software without specific, written prior
  12.  * permission. This software is supplied as is without expressed or
  13.  * implied warranties of any kind.
  14.  *
  15.  *      Campus Computing Sites, Sales, and Service
  16.  *      The University of Michigan
  17.  *      c/o Robert John Churchill
  18.  *      535 W. William Street
  19.  *      Ann Arbor, Michigan
  20.  *      +1-313-936-2528
  21.  *      rjc@ccs.itd.umich.edu
  22.  */
  23.  
  24. #include <Errors.h>
  25. #include <HyperXCmd.h>
  26. #include <Packages.h>
  27.  
  28. #include "authLibrary.h"
  29.  
  30. #define    XCMD_VERSION        1
  31.  
  32.     OSErr            Xcmdversion(XCmdPtr paramPtr,short refNum,Str255);
  33.     OSErr            Xauthenticate(XCmdPtr paramPtr,short refNum,Str255);
  34.     OSErr            Xkrbtgt(XCmdPtr paramPtr,short refNum,Str255);
  35.     OSErr            Xauthmanversion(XCmdPtr paramPtr,short refNum,Str255);
  36.     OSErr            Xlocalrealm(XCmdPtr paramPtr,short refNum,Str255);
  37.     OSErr            Xexpire(XCmdPtr paramPtr,short refNum,Str255);
  38.  
  39. typedef    struct    {
  40.     char            *name;
  41.     OSErr            (*proc)(XCmdPtr,short,Str255);
  42.     } _operations;
  43.  
  44.  
  45.  
  46. OSErr
  47. Xcmdversion(XCmdPtr paramPtr,short refNum,Str255 theString)
  48. {
  49. NumToString((long)XCMD_VERSION,theString);
  50. return(noErr);
  51. }
  52.  
  53.  
  54.  
  55. OSErr
  56. Xauthenticate(XCmdPtr paramPtr,short refNum,Str255 theString)
  57. {
  58.     OSErr            err;
  59.     short            ticketLen,version;
  60.     char            ticket[MAX_KTXT_LEN];
  61.  
  62. if (!(err=expireV4Ticket(refNum,(void *)"\pkrbtgt",NULL,NULL)))    {
  63.     err=getV4Ticket(refNum,(void *)&ticket,&ticketLen,(void *)"\pkrbtgt",    \
  64.         NULL,NULL,INFINITE_LIFETIME,PROMPT_FLAG);
  65.     if (!err || err==paramErr)    {
  66.         err=Xkrbtgt(paramPtr,refNum,theString);
  67.         }
  68.     }
  69. return(err);
  70. }
  71.  
  72.  
  73.  
  74. OSErr
  75. Xkrbtgt(XCmdPtr paramPtr,short refNum,Str255 theString)
  76. {
  77.     OSErr            err;
  78.     short            ticketNum;
  79.     _V4ticketInfo        theInfo;
  80.  
  81. ticketNum=0;
  82. while (!(err=getV4TicketNinfo(refNum,ticketNum++,&theInfo)))    {
  83.     if (!IUEqualString(theInfo.sName,"\pkrbtgt"))    {
  84.         BlockMove(&theInfo.pName[1],
  85.             &theString[theString[0]+1],
  86.             (unsigned)theInfo.pName[0]);
  87.         theString[0]+=(unsigned)theInfo.pName[0];
  88.         if (theInfo.pInstance[0])    {
  89.             theString[++theString[0]]='.';
  90.             BlockMove(&theInfo.pInstance[1],
  91.                 &theString[theString[0]+1],
  92.                 ((unsigned)theInfo.pInstance[0])+1L);
  93.             theString[0]+=(unsigned)theInfo.pInstance[0];
  94.             }
  95.         if (theInfo.pRealm[0])    {
  96.             theString[++theString[0]]='@';
  97.             BlockMove(&theInfo.pRealm[1],
  98.                 &theString[theString[0]+1],
  99.                 ((unsigned)theInfo.pRealm[0])+1L);
  100.             theString[0]+=(unsigned)theInfo.pRealm[0];
  101.             }
  102.         break;
  103.         }
  104.     }
  105. if (err==paramErr)    err=noErr;
  106. return(err);
  107. }
  108.  
  109.  
  110.  
  111. OSErr
  112. Xauthmanversion(XCmdPtr paramPtr,short refNum,Str255 theString)
  113. {
  114.     OSErr            err;
  115.     short            version;
  116.  
  117. if (!(err=openAuthMan(&refNum,&version)))    {
  118.     NumToString((long)version,theString);
  119.     }
  120. return(err);
  121. }
  122.  
  123.  
  124.  
  125. OSErr
  126. Xlocalrealm(XCmdPtr paramPtr,short refNum,Str255 theString)
  127. {
  128.     short            realmType;
  129.  
  130. return(getDefaultRealm(refNum,(void *)theString,&realmType));
  131. }
  132.  
  133.  
  134.  
  135. OSErr
  136. Xexpire(XCmdPtr paramPtr,short refNum,Str255 theString)
  137. {
  138. return(expireV4Ticket(refNum,NULL,NULL,NULL));
  139. }
  140.  
  141.  
  142.  
  143. short
  144. strlenandzero(char *p)
  145. {
  146.     short            theLen=1;        // length includes terminating zero
  147.  
  148. while (*p++)    ++theLen;
  149. return(theLen);
  150. }
  151.  
  152.  
  153.  
  154. pascal
  155. main(XCmdPtr paramPtr)
  156. {
  157.     Handle            param1;
  158.     OSErr            err;
  159.     Str255            theString;
  160.     short            len,loop,refNum,version=0;
  161.     _operations        operations[10];
  162.  
  163. operations[0].name="xcmdversion";    operations[0].proc=Xcmdversion;
  164. operations[1].name="authenticate";    operations[1].proc=Xauthenticate;
  165. operations[2].name="krbtgt";        operations[2].proc=Xkrbtgt;
  166. operations[3].name="authmanversion";    operations[3].proc=Xauthmanversion;
  167. operations[4].name="localrealm";    operations[4].proc=Xlocalrealm;
  168. operations[5].name="expire";        operations[5].proc=Xexpire;
  169. operations[6].name=NULL;        operations[6].proc=NULL;
  170.  
  171. if (!(err=openAuthMan(&refNum,&version)))    {
  172.     if (version < AUTHMAN_VERSION_CODE || paramPtr->paramCount<1)    {
  173.         err=-1;
  174.         }
  175.     else    {
  176.         param1=(paramPtr->params)[0];
  177.         HLock(param1);
  178.  
  179.         theString[0]=0;
  180.         for (loop=0; operations[loop].name; loop++)    {
  181.             len=strlenandzero(operations[loop].name);
  182.             if (!IUMagIDString(*param1,operations[loop].name,(long)len,(long)len))    {
  183.                 theString[0]=0;
  184.                 if (!(err=(*(operations[loop].proc))(paramPtr,refNum,theString)))    {
  185.                     paramPtr->returnValue=PasToZero(paramPtr,theString);
  186.                     }
  187.                 break;
  188.                 }
  189.             }
  190.         HUnlock(param1);
  191.         }
  192.     }
  193. if (err)        NumToString((long)err,theString);
  194. if (theString[0])    paramPtr->returnValue=PasToZero(paramPtr,theString);
  195. }
  196.